
package com.jf.cloud.multishop.controller.platform;

import com.jf.cloud.common.exception.LuckException;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.multishop.constant.AuditStatus;
import com.jf.cloud.multishop.dto.ShopCompanyDTO;
import com.jf.cloud.multishop.model.ShopCompany;
import com.jf.cloud.multishop.service.ShopCompanyService;
import com.jf.cloud.multishop.vo.ShopCompanyVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Objects;

/**
 * 商家工商信息
 *
 * @author zz
 */
@RestController("platformShopCompanyController")
@RequestMapping("/p/shop_company")
@Tag(name = "platform-商家工商信息")
public class ShopCompanyController {

    @Autowired
    private ShopCompanyService shopCompanyService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping
    @Operation(summary = "根据店铺id获取店铺工商信息" , description = "根据店铺id获取店铺工商信息")
    @Parameter(name = "status", description = "审核状态：1：已通过 0待审核 -1未通过" )
    public ServerResponseEntity<ShopCompanyVO> getShopCompanyByShopId(@RequestParam("shopId") Long shopId, @RequestParam(value = "status",required = false, defaultValue = "1") Integer status) {
        return ServerResponseEntity.success(shopCompanyService.getShopCompanyByShopIdAndStatus(shopId, status));
    }

    @PutMapping
    @Operation(summary = "更新店铺工商信息" , description = "更新店铺工商信息")
    public ServerResponseEntity<Void> editShopCompany(@RequestBody @Valid ShopCompanyDTO shopCompanyDTO) {
        if (Objects.isNull(shopCompanyDTO.getShopId())) {
            throw new LuckException("店铺id不能为空");
        }
        ShopCompany shopCompany = mapperFacade.map(shopCompanyDTO, ShopCompany.class);
        shopCompany.setStatus(AuditStatus.SUCCESSAUDIT.value());
        shopCompanyService.updateByShopId(shopCompany, shopCompany.getShopId(), 1);
        return ServerResponseEntity.success();
    }
}
